var customerUpdate = {
    classifyLists: [],//所有分类集合
    firstCategoryList: [],//一级分类集合
    secondCategoryList: [],//二级分类集合
    thirdCategoryList: [],//三级分类集合
    fourCategoryList: [],//四级分类集合
    searchClassifyObj: {},
    updateFlag: true,// true 新增 false 修改
    params: {
        spuName: '',//商品名称
        providerId: '',//服务商ID
        channelId: '',//客户编码
        channelName: '',//
        categoryId: '',// 分类ID
        classificationId: '',// 归类ID
        revenueCode: '',// 税类编码
        brandId: '',// 云采品牌ID
        brandName: '',//云采品牌名称
        definitionBrandName: '',// 自定义品牌名称（brandId这个为空，此字段就必传）
        restricted: '',//限制类型 默认0非限制类，1危化品，2管制刀具
        detail: '',//详情
        // material: '',//材质
        origin: '',//产地
        productQualifications: '',//商品资质
        operateUserId: JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,//操作人ID
        operateUserName: JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,// 操作人名称
        productQualificationAttachments:[]
    },// 新增修改参数
    skus: [],
    selectFirstClassify: '',//选择一级分类
    selectSecondClassify: '',//选择的二级分类
    selectThirdClassify: '',//选择的三级分类
    selectFourthClassify: '',//选择四级分类
    oneCategoryId: '',//修改一级分类id
    twoCategoryId: '',//修改二级分类id
    categoryId: '',// 修改三级分类id
    timer: null,//定时器标识
    saleAreas:null,//存储区域
    providerId:'',//
    channelId:'',//渠道id
    threeCategoryId: '',//修改三级分类
    customerId: '',//客户id
    init: function () {
        if (getQueryString("params")) {
            var paramsFlag = getQueryString("params");
        }
        if (paramsFlag == 'add') {
            $('#modifyClassify').hide();
            $('#modifyCustomer').hide();
            $('#modifytable').hide();
            $('#addClassify').show();
            $('#addCustomer').show();
            $('#addtable').show();
            $('#brandName').attr('ignore', '')
            this.updateFlag = true
        } else {
            if (getQueryString("spuId")) {
                var spuId = getQueryString("spuId");
                this.getDetailDataInfo(spuId)
            }
            $('#modifyClassify').show();
            $('#modifyCustomer').show();
            $('#modifytable').show();
            $('#addClassify').hide();
            $('#addCustomer').hide();
            $('#addtable').hide();
            this.ignoreFn();
            this.updateFlag = false;
        }
        this.addClick();
        this.findAllInfo();
        this.getListBrandInfo();
        this.addEventFn();
    },
    addClick: function () {
        // 校验信息
        $('#customerForm').Validform({
            ignore: ":hidden",//不验证的元素
            //ignore: ":hidden:not(select)",//不验证的元素
            tiptype: 2,
            callback: function (form) {
                customerUpdate.submitFn();
                return false
            }
        })
        // 新增表格事件
        $('#tableData').delegate('.unitId', 'keyup', function (e) {
            var unitName = $(this).val();
            var searchWarp = $(this).parent().parent().children().eq(2);
            $(searchWarp).show();
            customerUpdate.searchUnitInfo(unitName);
        });
        //新增点击筛选条件的某一项
        $('#tableData').delegate('.search-unit .unit-item', 'click', function () {
            var unitId = $(this).attr('data-unitId');
            var unitName = $(this).text();
            var inputValue = $(this).parent().parent().children().eq(0).children();
            var unitWarp = $(this).parent();
            var warpTd = $(this).parent().parent();
            $(warpTd).attr('data-unitId', unitId)
            $(inputValue).val(unitName);
            $(inputValue).focus();
            $(unitWarp).hide();
        })

        // 修改表格事件
        $('#modifyTableData').delegate('.unitId', 'keyup', function (e) {
            var unitName = $(this).val();
            var searchWarp = $(this).parent().parent().children().eq(2);
            $(searchWarp).show();
            customerUpdate.searchUnitInfo(unitName);
        });
        // 修改表格的某一项
        $('#modifyTableData').delegate('.search-unit .unit-item', 'click', function () {
            var unitId = $(this).attr('data-unitId');
            var unitName = $(this).text();
            var inputValue = $(this).parent().parent().children().eq(0).children();
            var unitWarp = $(this).parent();
            var warpTd = $(this).parent().parent();
            $(warpTd).attr('data-unitId', unitId)
            $(inputValue).val(unitName);
            $(inputValue).focus();
            $(unitWarp).hide();
        })

        // 选择已有品牌切换自定义品牌
        $('.addBrandName').on('click', function () {
            $('.add-brandName').hide();
            $('.add-definedName').show();
            $('#brandName').attr('ignore', 'ignore')
            $('#definitionBrandName').attr('ignore', '')
        });
        // 自定义品牌切换选择已有品牌
        $('.selectBrandName').on('click', function () {
            $('.add-brandName').show();
            $('.add-definedName').hide();
            $('#brandName').attr('ignore', '');
            $('#definitionBrandName').attr('ignore', 'ignore')
        });
        // 归类名称-查询税类编码
        $('#classifyName').on('change', function () {
            var revenueCode = $(this).find('option:selected').attr("data-revenueCode");
            $('#revenueCode').html(revenueCode)
        });
        // 归类名称-点击提示
        $('#classifyName').on('click', function () {
            if (!customerUpdate.categoryId) {
                layer.msg('请选择到末级分类!', {offset: "t"});
            }
        })
        // 点击一级分类查找二级分类
        $('#first').delegate('.classify-item', 'click', function () {
            var id = $(this).attr('data-id');
            var categoryNameFirst = $(this).text();
            customerUpdate.selectFirstClassify = categoryNameFirst + ' >'
            $('#inputProductClassify').val(customerUpdate.selectFirstClassify)
            var allFirst = $('.first-classify');
            $.each(allFirst, function (index, item) {
                $(item).removeClass('selectedClassify')
            })
            $(this).addClass('selectedClassify');
            customerUpdate.twoCategoryId = null;
            customerUpdate.threeCategoryId = null;
            customerUpdate.categoryId = null;
            $('#third').empty();
            $('#fourth').empty();
            // 归类名称清空
            var empty = '<option value="" selected>请选择归类名称</option>';
            $('#classifyName').html(empty);
            customerUpdate.renderSecondClassify(id);
            $('#inputProductClassify').focus();
        });
        // 点击二级查找三级
        $('#second').delegate('.classify-item', 'click', function () {
            var id = $(this).attr('data-id');
            var categoryNameSecond = $(this).text();
            customerUpdate.selectSecondClassify = customerUpdate.selectFirstClassify + categoryNameSecond + '>';
            $('#inputProductClassify').val(customerUpdate.selectSecondClassify)
            var allSecond = $('.second-classify');
            $.each(allSecond, function (index, item) {
                $(item).removeClass('selectedClassify')
            })
            $(this).addClass('selectedClassify');
            customerUpdate.threeCategoryId = null;
            customerUpdate.categoryId = null;
            // 归类名称清空
            var empty = '<option value="" selected>请选择归类名称</option>';
            $('#classifyName').html(empty);
            $('#revenueCode').html('');
            customerUpdate.renderThirdClassify(id);
        });
        // 点击三级查找四级分类
        $('#third').delegate('.classify-item', 'click', function () {
            var id = $(this).attr('data-id');
            var categoryNameThird = $(this).text();
            customerUpdate.selectThirdClassify = customerUpdate.selectSecondClassify + categoryNameThird +'>';
            $('#inputProductClassify').val(customerUpdate.selectThirdClassify)
            var allThird = $('.third-classify');
            $.each(allThird, function (index, item) {
                $(item).removeClass('selectedClassify')
            })
            $(this).addClass('selectedClassify');
            customerUpdate.categoryId = null;
            // 归类名称清空
            var empty = '<option value="" selected>请选择归类名称</option>';
            $('#classifyName').html(empty);
            $('#revenueCode').html('');
            customerUpdate.renderFourClassify(id);
        });

        // 点击四级分类
        $('#fourth').delegate('.classify-item', 'click', function () {
            var categoryId = $(this).attr('data-id');
            var categoryNameFourth = $(this).text();
            customerUpdate.selectFourthClassify = customerUpdate.selectThirdClassify + categoryNameFourth;
            $('#inputProductClassify').val(customerUpdate.selectFourthClassify)
            customerUpdate.categoryId = categoryId;
            var allFour = $('.four-classify');
            $.each(allFour, function (index, item) {
                $(item).removeClass('selectedClassify')
            });
            $(this).addClass('selectedClassify')
            customerUpdate.params.categoryId = categoryId;
            customerUpdate.getClassIficationAndRevenueInfo(categoryId)
        })

        // 输入框的键盘事件进行模糊搜索
        $('#inputProductClassify').on('input', function () {
            var classifyName = $('#inputProductClassify').val();
            //customerUpdate.delayFn(classifyName)
            clearTimeout(customerUpdate.timer);
            customerUpdate.timer = setTimeout(function () {
                customerUpdate.categoryListInfo(classifyName);
                $('#productClassify').show();
            }, 1000)
        });
        // 输入框失去焦点搜索框隐藏
        $(document).on('click', function () {
            $('#productClassify').hide();
            $('.search-brand').hide();
        })
        // 模糊搜索结果选择
        $('.classify-warp').delegate('.classify-item', 'click', function () {
            var categoryName = $(this).attr('data-name');
            var dataItem = JSON.parse($(this).attr('data-item'));
            var firstId = dataItem.firstUuid;
            var secondId = dataItem.secondUuid;
            var thirdId = dataItem.thirdUuid;
            var fourthId = dataItem.uuid;
            customerUpdate.renderSecondClassify(firstId);
            customerUpdate.renderThirdClassify(secondId);
            customerUpdate.renderFourClassify(thirdId);
            customerUpdate.params.categoryId = fourthId;
            customerUpdate.categoryId = fourthId;
            customerUpdate.getClassIficationAndRevenueInfo(fourthId)
            // 一级分类渲染
            $.each($('.first-classify'), function (index, item) {
                $(item).removeClass('selectedClassify')
                if (firstId == $(item).attr('data-id')) {
                    $(item).addClass('selectedClassify')
                }
            })
            // 二级分类样式渲染
            $.each($('.second-classify'), function (index, item) {
                $(item).removeClass('selectedClassify')
                if (secondId == $(item).attr('data-id')) {
                    $(item).addClass('selectedClassify')
                }
            })
            // 三级分类样式渲染
            $.each($('.third-classify'), function (index, item) {
                $(item).removeClass('selectedClassify')
                if (thirdId == $(item).attr('data-id')) {
                    $(item).addClass('selectedClassify')
                }
            })
            // 四级分类的样式渲染
            $.each($('.four-classify'), function (index, item) {
                $(item).removeClass('selectedClassify');
                if (fourthId == $(item).attr('data-id')) {
                    $(item).addClass('selectedClassify')
                }
            })
            // 拆分分类内容
            var categoryAry = categoryName.split('>');
            customerUpdate.selectFirstClassify = categoryAry[0] + '>';
            customerUpdate.selectSecondClassify = categoryAry[0] + '>' + categoryAry[1] + '>';
            customerUpdate.selectThirdClassify = categoryAry[0] + '>' + categoryAry[1] + '>' + categoryAry[2];
            customerUpdate.selectFourthClassify = categoryAry[0] + '>' + categoryAry[1] + '>' + categoryAry[2] + '>' + categoryAry[3];
            $('#inputProductClassify').val(categoryName)
            $('#productClassify').hide();

        });
        // 选择服务商查询结果
        $('#serviceProvider').on('change', function () {
            var providerId = $(this).val();
            customerUpdate.params.providerId = providerId;
            customerUpdate.providerId = providerId;
            // 商品分类清空
            $('#inputProductClassify').val('');
            $('#first').html('');
            $('#second').html('');
            $('#third').html('');
            $('#fourth').html('');
            // 归类名称清空
            var empty = '<option value="" selected>请选择归类名称</option>';
            $('#classifyName').html(empty);
            // 税类编码清空
            $('#revenueCode').html('');
            customerUpdate.getCooperationByProviderInfo(providerId);

        });
        //点击客户专属客户提示请选择服务商
        $('#productCustomer').on('click', function () {
            var providerId = $('#serviceProvider').find('option:selected').val();
            if (!providerId) {
                layer.msg('请选择服务商!', {offset: "t"});
            }
        });
        // 选择客户专有渠道
        $('#productCustomer').on('change', function () {
            // 商品分类
            var inputProductClassifyValue = $('#inputProductClassify').val();
            // 归类名称
            var classifyNameValue = $('#classifyName').find('option:selected').val();
            if (inputProductClassifyValue || classifyNameValue) {
                layer.msg('商品分类与归类发生变化，请重新选择!', {offset: "t"});
            }
            var channelId = $('#productCustomer').find('option:selected').val();
            if (channelId) {
                customerUpdate.getClassifyInfo(channelId);
                customerUpdate.customerId = channelId
                $('#second').html('');
                $('#third').html('');
                $('#inputProductClassify').val('');
                customerUpdate.params.channelId = $(this).val();
                customerUpdate.channelId = $(this).val();
                customerUpdate.saleAreas =null;
                $('.saleAreaLists').empty();//清空上次操作数据
                // 归类名称清空
                var empty = '<option value="" selected>请选择归类名称</option>';
                $('#classifyName').html(empty);
                // 税类编码清空
                $('#revenueCode').html('');
                customerUpdate.categoryId = null;
                customerUpdate.params.channelName = $('#productCustomer').find('option:selected').text();
                getAreasHandler();
            }
        });

        function getAreasHandler () {
            var params = {
                providerId: customerUpdate.providerId,
                channelId: customerUpdate.channelId
            }
            var successData = function(data){
                if(data.code == 0){
                    if (data.data && data.data[0].saleAreas) {
                        customerUpdate.saleAreas = data.data[0].saleAreas;
                        if (customerUpdate.saleAreas.length > 0) {
                            if (customerUpdate.saleAreas[0].code == 0) {
                                var strArea = '';
                                $.each(customerUpdate.saleAreas, function (index, item) {
                                    strArea += ' <li style="cursor: pointer;display: inline-block;margin-right: 7px" data-code="'+item.code+'">' + item.name + '' +'</li>'
                                });
                            } else {
                                var strArea = '';
                                $.each(customerUpdate.saleAreas, function (index, item) {
                                    strArea += ' <li style="cursor: pointer;display: inline-block;margin-right: 7px" data-code="'+item.code+'">' + item.name + '' +
                                        ' <span style="color: #0a60d6">(' + item.children.length + ')</span>' +
                                        '</li>'
                                });
                            }
                            
                            $('.saleAreaLists').html(strArea);
                        }
                    }
                }
            }

            return web.doAjax(root.serviceProviderManagement.findProviderCooperationByProviderIdAndChannelId, 'post', params, successData, 2);
        }
        // 品牌商品模糊搜索
        $('#brandName').on('keyup', function () {
            var brandNameValue = $('#brandName').val();
            $('.search-brand').show();
            customerUpdate.getListBrandInfo(brandNameValue);
        })
        // 点击品牌商品
        $('.brand-warp').delegate('.brand-item', 'click', function () {
            var brandId = $(this).attr('data-brandId');
            var brandName = $(this).text();
            $('#brandName').val(brandName);
            customerUpdate.params.brandId = brandId;
            customerUpdate.params.brandName = brandName;
            $('.search-brand').hide();
            $('#brandName').focus();
        });
        // 点击上传商品图片
        $('#imgOperate').unbind().on('click', function (e) {
            $('#imgs').trigger('click')
        });
        // 上传图片
        $('#imgs').unbind().change(function () {
            
            var file = $("#imgs")[0].files[0];

            //初始化FileReader对象
            var reader = new FileReader();
            //读取图片文件
            reader.readAsDataURL(file);
            reader.onload = function (e) {
            //初始化JavaScript图片对象
            var image = new Image();
            //FileReader获得Base64字符串
            image.src = e.target.result;
            image.onload = function () {
            if (this.height != 800) {
                layer.msg('图片尺寸需为800*800');
                return false;
            } else if (this.width != 800) {
                layer.msg('图片尺寸需为800*800');
                return false;
            }else{
                var formData = new FormData();
                formData.set('files', file);
                customerUpdate.uploadImage(formData);
            }
          }
        }
        })
        // 上传pdf文件
        $('#pdfOperate').unbind().on('click', function (e) {
            $('#filePdf').trigger('click')
        });
        $('#filePdf').unbind().on('change', function () {
            var formData = new FormData();
            formData.set('file', $("#filePdf")[0].files[0]);
            customerUpdate.uploadQualificationInfo(formData)
        });
        
        // 新增规格
        $('#addSpecification').unbind().on('click', function () {
            var str = ' <tr class="add_tr" style="height: 60px">' +
                '                <td class="col-9-1  text-l">' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input type="text" class="input-text radius specifications"' +
                '                               maxlength="127" datatype="/^[\\s\\S]{1,127}$/" placeholder="请输入规格" number="127" maxlength="127" nullmsg="请输入规格" errormsg="请输入规格" autocomplete="off">' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                   </span>' +
                '                </td>' +
                '                <td class="col-9-1  text-l">' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input type="text" class="input-text radius color" placeholder="请输入颜色" >' +
                '                    </div>' +
                '                </td>\n' +
                '                <td class="col-9-1  text-l">' +
                '                    <label class="form-label f-l">¥</label>' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input type="text" class="input-text radius channelPrice"' +
                '                               nullmsg="请输入售价"' +
                '                               errormsg="请输入售价"' +
                '                               autocomplete="off"' +
                '                               datatype="*"' +
                '                               placeholder="请输入售价" onkeyup="!/^(\\d+\\.?)?\\d{0,2}$/.test(this.value)?(this.value=this.value.substring(0, this.value.length-1)): \'\'"/>\n' +
                '                    </div>\n' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>\n' +
                '                <td class="col-9-1  text-l" style="position:relative;">' +
                '                    <div class="col-sm-8" style="width: 75%">' +
                '                        <input type="text" style="width:180px"  class="input-text radius unitId"' +
                '                               nullmsg="请输入计量单位"' +
                '                               errormsg="请输入计量单位"' +
                '                               placeholder="请输入计量单位"' +
                '                               datatype="*"' +
                '                               autocomplete="off"' +
                '                        >' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                    <ul class="search-unit">' +
                '                        <!--<li class="unit-item">1</li>-->' +
                '                    </ul>' +
                '                </td>' +
                '                <td class="col-9-1  text-l">' +
                '                   <div class="formControls col-sm-8" style="width: 75%">' +
                '                   <input type="text" class="input-text radius deliveryDay"' +
                '                           nullmsg="请输入预计出货日"' +
                '                           errormsg="请输入预计出货日"' +
                '                           autocomplete="off"' +
                '                           datatype="*"' +
                '                           placeholder="请输入预计出货日"' +
                '                           maxlength="5"' +
                '                           number="5"' +
                '                           onkeyup="value=value.replace(/[^\\d]/g, \'\').replace(/^0{1,}/g,\'\')"' +
                '                    >' +
                '                       <span style="position: absolute;top: 4px;margin-left: 6px;">天</span>'+
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '               <td class="col-9-1  text-l">' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input type="text" class="input-text radius miniNum"' +
                '                               nullmsg="请输入最小起订量"' +
                '                               errormsg="请输入最小起订量"' +
                '                               autocomplete="off"' +
                '                               datatype="*"' +
                '                               placeholder="请输入最小起订量"' +
                '                               maxlength="5"' +
                '                               number="5"' +
                '                               onkeyup="value=value.replace(/[^\\d]/g, \'\').replace(/^0{1,}/g,\'\')"' +
                '                        >' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '                 <td class="col-9-1 text-l">' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input' +
                '                                type="text" class="input-text radius maxLong"' +
                '                                onkeyup="value=value.replace(/[^\\d^\\.]+/g,\'\').replace(\'.\',\'$#$\').replace(/\\./g,\'\').replace(\'$#$\',\'.\')"\n' +
                '                                placeholder="请输入最长边"' +
                '                                maxlength="10"' +
                '                                nullmsg="请输入最长边"' +
                '                                errormsg="小数点后最多输入6位有效数字"' +
                '                                number="10"' +
                '                                datatype="/^[0-9]+(.[0-9]{1,6})?$/"' +
                '                        >' +
                '                        <span style="position: absolute;top: 4px;margin-left: 6px;width: 18px;display: inline-block" >cm</span>\n' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '                <td class="col-9-1 text-l">' +
                '                    <div class="formControls col-sm-8"  style="width: 75%">' +
                '                        <input' +
                '                                type="text" class="input-text radius max-volume"' +
                '                                placeholder="请输入体积"' +
                '                                onkeyup="value=value.replace(/[^\\d^\\.]+/g,\'\').replace(\'.\',\'$#$\').replace(/\\./g,\'\').replace(\'$#$\',\'.\')"\n' +
                '                                maxlength="10"' +
                '                                nullmsg="请输入体积"' +
                '                                errormsg="小数点后最多输入6位有效数字"' +
                '                                autocomplete="off"' +
                '                                number="10"' +
                '                                datatype="/^[0-9]+(.[0-9]{1,6})?$/"' +
                '                        >' +
                '                        <span style="position: absolute;top: 4px;margin-left: 6px;width: 18px;display: inline-block">m³</span>\n' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '                <td class="col-9-1 text-l">' +
                '                    <div class="formControls col-sm-8"  style="width: 75%">' +
                '                        <input type="text" class="input-text radius weight"' +
                '                               nullmsg="请输入重量"' +
                '                               errormsg="小数点后最多输入6位有效数字"' +
                '                               autocomplete="off"' +
                '                               datatype="/^[0-9]+(.[0-9]{1,6})?$/"' +
                '                               placeholder="请输入重量"' +
                '                               maxlength="10"' +
                '                               number="10"' +
                '                               onkeyup="value=value.replace(/[^\\d]/g, \'\').replace(/^{1,}/g,\'\')"' +
                '                        >' +
                '                        <span style="position: absolute;top: 4px;margin-left: 6px;width: 15px;display: inline-block">kg</span>' +
                '                        <img src="../../../img/delete.png" alt="这是一张图片" class="deleteImg" onclick="customerUpdate.deleteModifyTd(this)">' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '            </tr>'
            $('#tableData').append(str)
        });
        // 修改- 新增规格
        $('#modifySpecification').unbind().on('click', function () {
            var str = '<tr class="update-tr" style="height: 60px">' +
                '            <td class="col-10-1 text-l" data-skuId="">' +
                '                <div></div>' +
                '            </td>' +
                '            <td class="col-10-1 text-l">' +
                '                <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input type="text" class="input-text radius specifications"' +
                '                               maxlength="127" datatype="/^[\\s\\S]{1,127}$/" placeholder="请输入规格" number="127" maxlength="127" nullmsg="请输入规格" errormsg="请输入规格" autocomplete="off">' +
                '                </div>' +
                '                <span class="Validform_checktip">' +
                '                       <span class="Validform_checktip"></span>' +
                '                </span>' +
                '            </td>' +
                '            <td class="col-10-1 text-l">' +
                '                <div class="formControls col-sm-8" style="width: 75%">' +
                '                    <input type="text" class="input-text radius color" placeholder="请输入颜色">' +
                '                </div>' +
                '            </td>' +
                '            <td class="col-10-1 text-l">' +
                '                <label class="form-label f-l">¥</label>' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input type="text" class="input-text radius channelPrice"' +
                '                               nullmsg="请输入售价"' +
                '                               errormsg="请输入售价"' +
                '                               autocomplete="off"' +
                '                               datatype="*"' +
                '                               placeholder="请输入售价" onkeyup="!/^(\\d+\\.?)?\\d{0,2}$/.test(this.value)?(this.value=this.value.substring(0, this.value.length-1)): \'\'"/>\n' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                   </span>' +
                '            </td>' +
                '            <td class="col-10-1 text-l" style="position:relative;">' +
                '                <div class="col-sm-7 ml-5" >' +
                '                    <input type="text"  style="width: 145px;" class="input-text radius unitId"' +
                '                               nullmsg="请输入计量单位"' +
                '                               errormsg="请输入计量单位"' +
                '                               placeholder="请输入计量单位"' +
                '                               autocomplete="off"' +
                '                               datatype="*"' +
                '                               autocomplete="off"' +
                '                        >' +
                '                </div>' +
                '                 <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                   </span>' +
                '                <ul class="search-unit" style=" width: 142px;margin-left: 15px">' +
                '                </ul>' +
                '            </td>' +
                '            <td class="col-10-1 text-l" >' +
                '                   <div class="formControls col-sm-8" style="width: 75%">' +
                '                  <input type="text" class="input-text radius deliveryDay"' +
                '                           nullmsg="请输入预计出货日"' +
                '                           errormsg="请输入预计出货日"' +
                '                           autocomplete="off"' +
                '                           datatype="*"' +
                '                           placeholder="请输入预计出货日"' +
                '                           maxlength="5"' +
                '                           number="5"' +
                '                           onkeyup="value=value.replace(/[^\\d]/g, \'\').replace(/^0{1,}/g,\'\')"' +
                '                    >' +
                '                       <span style="position: absolute;top: 4px;margin-left: 6px;">天</span>'+
                '               </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '            </td>' +
                '           <td class="col-10-1 text-l">' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input type="text" class="input-text radius deliveryDay"' +
                '                               nullmsg="请输入最小起订量"' +
                '                               errormsg="请输入最小起订量"' +
                '                               autocomplete="off"' +
                '                               datatype="*"' +
                '                               placeholder="请输入最小起订量"' +
                '                               maxlength="5"' +
                '                               number="5"' +
                '                               onkeyup="value=value.replace(/[^\\d]/g, \'\').replace(/^0{1,}/g,\'\')"' +
                '                        >' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '                <td class="col-10-1 text-l">' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input' +
                '                                type="text" class="input-text radius modify_maxLong"' +
                '                                onkeyup="value=value.replace(/[^\\d^\\.]+/g,\'\').replace(\'.\',\'$#$\').replace(/\\./g,\'\').replace(\'$#$\',\'.\')"' +
                '                                placeholder="请输入最长边"' +
                '                                maxlength="10"' +
                '                                nullmsg="请输入最长边"' +
                '                                errormsg="小数点后最多输入6位有效数字"' +
                '                                number="10"' +
                '                                datatype="/^[0-9]+(.[0-9]{1,6})?$/"' +
                '                        >' +
                '                        <span style="position: absolute;top: 4px;margin-left: 6px;width: 18px;display: inline-block" >cm</span>' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '                 <td class="col-10-1 text-l">' +
                '                    <div class="formControls col-sm-8"  style="width: 75%">' +
                '                        <input' +
                '                                type="text" class="input-text radius modify_maxVolume"' +
                '                                placeholder="请输入体积"' +
                '                                onkeyup="value=value.replace(/[^\\d^\\.]+/g,\'\').replace(\'.\',\'$#$\').replace(/\\./g,\'\').replace(\'$#$\',\'.\')"' +
                '                                maxlength="10"' +
                '                                nullmsg="请输入体积"' +
                '                                errormsg="小数点后最多输入6位有效数字"' +
                '                                autocomplete="off"' +
                '                                number="10"' +
                '                                datatype="/^[0-9]+(.[0-9]{1,6})?$/"' +
                '                        >' +
                '                        <span style="position: absolute;top: 4px;margin-left: 6px;width: 18px;display: inline-block">m³</span>' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '                <td class="col-10-1 text-l">' +
                '                    <div class="formControls col-sm-8"  style="width: 75%">' +
                '                        <input type="text" class="input-text radius modify_weight"' +
                '                               nullmsg="请输入重量"' +
                '                               errormsg="小数点后最多输入6位有效数字"' +
                '                               autocomplete="off"' +
                '                               datatype="/^[0-9]+(.[0-9]{1,6})?$/"' +
                '                               placeholder="请输入重量"' +
                '                               maxlength="10"' +
                '                               number="10"' +
                '                               onkeyup="value=value.replace(/[^\\d]/g, \'\').replace(/^{1,}/g,\'\')"' +
                '                        >' +
                '                        <span style="position: absolute;top: 4px;margin-left: 6px;width: 15px;display: inline-block">kg</span>' +
                '                        <img src="../../../img/delete.png" alt="这是一张图片" class="deleteImg" onclick="customerUpdate.deleteModifyTd(this)">' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '        </tr>';
            $('#modifyTableData').append(str)
        });
        // 设置区域
        $('.setArea').unbind().on('click', function () {
            sessionStorage.setItem('saleAreas',JSON.stringify(customerUpdate.saleAreas));
            var channelId = customerUpdate.channelId;
            var providerId = customerUpdate.providerId;
            if(!providerId){
                return layer.msg('请选择商品专属渠道')
            }
            layer_show("设置区域", "../../serviceProvider/appointArea.html?channelId="+channelId+"&providerId="+providerId, "500", "400", {offset: 't'})
        });
        // 销售区域触发事件
        $('.saleAreaLists').delegate('li', 'click', function () {
            var provinceCode = $(this).attr('data-code');
            var str = '';
            $.each(customerUpdate.saleAreas, function (index, item) {
                if(item.code == provinceCode){
                    $.each(item.children,function(index,itm){
                        str += '<span>' + itm.name + '、</span>'
                    })
                }

            })
            layer.alert(str, {title: '销售区域', offset: 't'})
        })
    },
    // 事件监听方法
    addEventFn:function(){
        document.addEventListener('saveSaleAreasEvent',function(event){
            customerUpdate.saleAreas = event.detail.saleAreas;
            var strArea = '';
            $.each(customerUpdate.saleAreas, function (index, item) {
                if(item.code == 0){ //全国
                    strArea = '<li>全国</li>'
                }else{
                    strArea += ' <li style="cursor: pointer;display: inline-block;margin-right: 7px" data-code="'+item.code+'">' + item.name + '' +
                        ' <span style="color: #0a60d6">(' + item.children.length + ')</span>' +
                        '</li>'
                }

            });
            $('.saleAreaLists').html(strArea);
        });

    },
    // 延迟执行函数
    delayFn: function (value) {
        clearTimeout(customerUpdate.timer);
        customerUpdate.timer = setTimeout(function () {
            customerUpdate.categoryListInfo(value);
            $('#productClassify').show();
        }, 1000)
    },
    // 对于隐藏元素去除校验信息
    ignoreFn: function () {
        // 服务商
        $('#serviceProvider').attr('ignore', 'ignore')
        //商品专属渠道
        $('#productCustomer').attr('ignore', 'ignore')
        // 商品信息规格校验--新增
        $('.specifications').attr('ignore', 'ignore')
        // 商品信息规格校验--售价
        $('.channelPrice').attr('ignore', 'ignore');
        // 商品信息规格校验 --新增计量单位
        $('.unitId').attr('ignore', 'ignore');
        // 商品信息规格校验 --- 预计出货日期
        $('.deliveryDay').attr('ignore', 'ignore');
        // 商品信息规格校验 --- 最小起订量
        $('.miniNum').attr('ignore', 'ignore');
        //商品信息规格校验 --- 最长边
        $('.maxLong').attr('ignore', 'ignore');
        //商品信息规格校验 --- 体积
        $('.volume').attr('ignore', 'ignore');
        //商品信息规格校验 --- 重量
        $('.weight').attr('ignore', 'ignore');
    },
    // 提交信息
    submitFn: function () {
        var flag = customerUpdate.parameterChecked();
        var productName = $('#productName').val(); // 商品名称
        var limitType = $('input[name="radio1"]:checked').val();
        // var material = $('#material').val();//材质
        var origin = $('#origin').val();//产地
        var spuImages = [];
        // 图片数据渲染
        var imageLists = $('.itemimage');
        $.each(imageLists, function (index, item) {
            var obj = {};
            obj.attachmentUrl = $(item).attr('src');
            obj.attachmentOriginalName = $(item).attr('data-name');
            spuImages.push(obj)
        })
        var definitionBrandName = $('#definitionBrandName').val()//自定义品牌
        customerUpdate.params.revenueCode = $("#classifyName").find("option:selected").attr("data-revenueCode");// 税类编码
        customerUpdate.params.restricted = limitType;
        customerUpdate.params.spuName = productName;
        customerUpdate.params.detail = UE.getEditor('editor').getContent();
        customerUpdate.params.origin = origin;
        // customerUpdate.params.material = material;
        customerUpdate.params.skus = customerUpdate.skus;
        customerUpdate.params.spuImages = spuImages;
        customerUpdate.params.classificationId = $("#classifyName").find("option:selected").val();
        customerUpdate.params.saleAreas = customerUpdate.saleAreas;
        // 品牌的选择
        if ($('.add-brandName').css('display') == 'block') { // 品牌显示
            customerUpdate.params.definitionBrandName = '';//自定义品牌为空
        } else { // 自定义品牌显示
            customerUpdate.params.definitionBrandName = definitionBrandName;
            customerUpdate.params.brandId = '';
            customerUpdate.params.brandName = ''
        }
        if (flag) {
            //$('.buttonLeft-name').attr('disabled', true)
            if (customerUpdate.updateFlag) { // 添加
                var addTr = $('.add_tr');
                var addSkus = [];
                if (addTr.length > 0) {
                    $.each(addTr, function (index, item) {
                        var addDataTd = $(item).children();
                        var obj = {
                            specifications: addDataTd.eq(0).find('input').val(),
                            color: addDataTd.eq(1).find('input').val(),
                            channelPrice: addDataTd.eq(2).find('input').val(),
                            unitId: addDataTd.eq(3).attr('data-unitId'),
                            deliveryDay: addDataTd.eq(4).find('input').val(),// 发货日期
                            miniOrder: addDataTd.eq(5).find('input').val(),// 最小起订量
                            skuId: '',
                            skuCode: '',
                            maxLength:addDataTd.eq(6).find('input').val(),//最长边
                            volume:addDataTd.eq(7).find('input').val(),//体积
                            weight:addDataTd.eq(8).find('input').val()// 重量
                        }
                        addSkus.push(obj)
                    })
                }
                customerUpdate.params.skus = addSkus;
                customerUpdate.saveProductByAdminInfo(customerUpdate.params);
            } else { // 修改
                // 修改规格信息
                var updateTr = $('.update-tr');
                var skus = [];
                if (updateTr.length > 0) {
                    $.each(updateTr, function (index, item) {
                        var updateTd = $(item).children();
                        var obj = {
                            specifications: updateTd.eq(1).find('input').val(),
                            color: updateTd.eq(2).find('input').val(),
                            channelPrice: updateTd.eq(3).find('input').val(),
                            unitId: updateTd.eq(4).attr('data-unitId'),
                            deliveryDay: updateTd.eq(5).find('input').val(),// 发货日期
                            miniOrder: updateTd.eq(6).find('input').val(),// 最小起订量
                            skuId: updateTd.eq(0).attr('data-skuId'),
                            skuCode: updateTd.eq(0).find('div').html(),
                            maxLength:updateTd.eq(7).find('input').val(),//最长边
                            volume:updateTd.eq(8).find('input').val(),//体积
                            weight:updateTd.eq(9).find('input').val()// 重量
                        }
                        skus.push(obj)
                    })
                }
                customerUpdate.params.skus = skus;
                customerUpdate.updateProductByAdminInfo(customerUpdate.params)
            }
        } else {
            //$('.buttonLeft-name').attr('disabled', false)
        }
    },
    // 删除-修改规格信息新增一栏
    deleteModifyTd: function (nowTr) {
        $(nowTr).parent().parent().parent().remove()
    },
    // 查询四级分类
    getClassifyInfo: function (customerId) {
        var params = {
            customerId: customerId,
            categoryName: ''
        }
        var successData = function (data) {
            if (data.errorCode == 0) {
                if (data.data) {
                    var firstCategoryList = data.data.firstCategoryList;
                    customerUpdate.firstCategoryList = data.data.firstCategoryList;
                    customerUpdate.secondCategoryList = data.data.secondCategoryList;
                    customerUpdate.thirdCategoryList = data.data.thirdCategoryList;
                    customerUpdate.fourCategoryList = data.data.categoryList;
                    customerUpdate.renderFirstClassify(firstCategoryList);
                    customerUpdate.productClassify();
                }

            }
        }
        return web.doAjax(root.serviceProviderManagement.selectChannelProductRule, 'post', params, successData, 1);
    },

    // 分类模糊查询
    categoryListInfo: function (name) {
        var params = {
            customerId: customerUpdate.customerId,
            categoryName: name
        }
        var successData = function (data) {
            if (data.errorCode == 0) {
                var result = data.data.categoryAllList;
                customerUpdate.renderSearchClassify(result)
            }
        }
        return web.doAjax(root.serviceProviderManagement.selectChannelProductRule, 'post', params, successData, 1);
    },
    renderSearchClassify: function (data) {
        var str = '';
        if (data.length > 0) {
            data.forEach(function (item) {
                var itemStr = JSON.stringify(item);
                str += '  <li   class="classify-item"  data-item=' + itemStr + '    data-name="' + item.firstCategoryName + '>' + item.secondCategoryName + '>' + item.thirdCategoryName + '>' + item.categoryName + '">' +
                    '                                <span>' + item.firstCategoryName + '</span>' +
                    '                                <span> > </span>' +
                    '                                <span>' + item.secondCategoryName + '</span>' +
                    '                                <span> > </span>' +
                    '                                <span>' + item.thirdCategoryName + '</span>' +
                    '                                <span> > </span>' +
                    '                                <span>' + item.categoryName + '</span>' +
                    '                            </li>';
            })
        } else {
            str = '<li> 暂无数据 </li>'
        }

        $('.classify-warp').html(str)
    },

    // 渲染一级分类
    renderFirstClassify: function (result) {
        var str = '';
        if (result.length > 0) {
            $.each(result, function (index, item) {
                str += '<li class="classify-item first-classify" data-id="' + item.uuid + '">' + item.categoryName + '</li>'
            });
        } else {
            str += '<li class="classify-item">暂无分类商品</li>'
        }


        $('#first').html(str);
        if (customerUpdate.oneCategoryId) {
            var firstClassify = $('.first-classify');
            $.each(firstClassify, function (index, item) {
                var dataId = $(item).attr('data-id');
                if (dataId == customerUpdate.oneCategoryId) {
                    $(item).addClass('selectedClassify')
                }
            });
            customerUpdate.renderSecondClassify(customerUpdate.oneCategoryId)
        }
    },
    // 渲染二级分类
    renderSecondClassify: function (id) {
        var str = '';
        if (customerUpdate.secondCategoryList.length > 0) {
            var secondLists = customerUpdate.secondCategoryList.filter(function (item) {
                return id == item.parentUuid
            });
            $.each(secondLists, function (index, item) {
                str += '<li class="classify-item second-classify" data-id="' + item.uuid + '">' + item.categoryName + '</li>'
            });
        } else {
            str += '<li class="classify-item">暂无分类商品</li>'
        }
        $('#second').html(str);
        if (customerUpdate.twoCategoryId) {
            var secondClassify = $('.second-classify');
            $.each(secondClassify, function (index, item) {
                var dataId = $(item).attr('data-id');
                if (dataId == customerUpdate.twoCategoryId) {
                    $(item).addClass('selectedClassify')
                }
            });
            customerUpdate.renderThirdClassify(customerUpdate.twoCategoryId)
        }
    },
    // 渲染三级分类
    renderThirdClassify: function (id) {
        var str = '';
        if (customerUpdate.thirdCategoryList.length > 0) {
            var thirdLists = customerUpdate.thirdCategoryList.filter(function (item) {
                return id == item.parentUuid
            });
            $.each(thirdLists, function (index, item) {
                str += '<li class="classify-item third-classify" data-id="' + item.uuid + '">' + item.categoryName + '</li>'
            });
        } else {
            str += '<li class="classify-item">暂无分类商品</li>'
        }
        $('#third').html(str);
        if (customerUpdate.categoryId) {
            var thirdClassify = $('.third-classify');
            $.each(thirdClassify, function (index, item) {
                var dataId = $(item).attr('data-id');
                if (dataId == customerUpdate.threeCategoryId) {
                    $(item).addClass('selectedClassify')
                }
            });
            customerUpdate.renderFourClassify(customerUpdate.threeCategoryId)
        }
    },
    // 渲染四级分类 fourCategoryList
    renderFourClassify: function (id) {
        var str = '';
        if (customerUpdate.fourCategoryList.length > 0) {
            var fourLists = customerUpdate.fourCategoryList.filter(function (item) {
                return id == item.parentUuid
            });
            $.each(fourLists, function (index, item) {
                str += '<li class="classify-item four-classify" data-id="' + item.uuid + '">' + item.categoryName + '</li>'
            });
        } else {
            str += '<li class="classify-item">暂无分类商品</li>'
        }
        $('#fourth').html(str);
        if (customerUpdate.categoryId) {
            var fourClassify = $('.four-classify');
            $.each(fourClassify, function (index, item) {
                var dataId = $(item).attr('data-id');
                if (dataId == customerUpdate.categoryId) {
                    $(item).addClass('selectedClassify')
                }
            });
        }
    },

    // 重构商品分类数据
    productClassify: function () {
        var obj = {}
        $.each(customerUpdate.thirdCategoryList, function (index, item) {
            var ary = [];
            var secondClassify = customerUpdate.secondCategoryList.filter(function (item1) {
                return item.parentCateId == item1.categoryId;
            });
            $.each(secondClassify, function (index, item2) {
                var firstClassify = customerUpdate.firstCategoryList.filter(function (item3) {
                    return item2.parentCateId == item3.categoryId;
                });
                ary.push(item)
                ary.push(item2)
                ary.push(firstClassify[0])
                obj[item.categoryName + '' + item2.categoryName + '' + firstClassify[0].categoryName] = ary;

            })
        });
        customerUpdate.searchClassifyObj = obj;
    },
/*    // 渲染商品分类查询结果
    renderSearchClassify: function (value) {
        var obj = customerUpdate.searchClassifyObj;
        var ary = [];
        var str = '';
        for (var key in obj) {
            if (key.indexOf(value) > -1) {
                ary.push(obj[key])
            }
        }
        if (ary.length > 0) {
            ary.forEach(function (item) {
                var itemStr = JSON.stringify(item);
                str += '  <li    data-item=' + itemStr + '   class="classify-item" data-name="' + item[2].categoryName + '>' + item[1].categoryName + '>' + item[0].categoryName + '">' +
                    '                                <span>' + item[2].categoryName + '</span>' +
                    '                                <span> > </span>' +
                    '                                <span>' + item[1].categoryName + '</span>' +
                    '                                <span> > </span>' +
                    '                                <span>' + item[0].categoryName + '</span>' +
                    '                            </li>';
                $('.classify-warp').html(str)
            })
        }
    },*/
    // 获取服务商数据
    findAllInfo: function () {
        var params = {
            status: 1,
            name: ''
        }
        var successData = function (data) {
            if (data.code == 0) {
                if (data.data && data.data.length > 0) {
                    var result = data.data;
                    var str = ''
                    result.forEach(function (item) {
                        str += '<option value="' + item.id + '">' + item.name + '</option>'
                    });
                    var newStr = '<option value="" selected>请选择服务商</option>' + str
                    $('#serviceProvider').html(newStr)
                } else {
                    var emptyStr = '<option value="">请选择服务商</option>' + '<option value="">暂无服务商</option>';
                    $('#serviceProvider').html(emptyStr)
                }
            }
        }
        return web.doAjax(root.serviceProviderManagement.findAll, 'post', params, successData, 2);
    },
    // 获取专属渠道
    getCooperationByProviderInfo: function (providerId) {
        var params = {
            providerId: providerId
        }
        var successData = function (data) {
            if (data.code == 0) {
                if (data.data.length > 0) {
                    var result = data.data;
                    var str = '';
                    result.forEach(function (item) {
                        str += '<option value="' + item.channelId + '">' + item.channelName + '</option>'
                    });
                    var newStr = ' <option value="">请选择专属渠道</option>' + str;
                    $('#productCustomer').html(newStr)
                } else {
                    var emptyStr = '<option value="">请选择专属渠道</option>' + '<option value="">暂无商品专属渠道</option>';
                    $('#productCustomer').html(emptyStr)
                }
            }
        }
        return web.doAjax(root.serviceProviderManagement.findProviderCooperationByProviderId, 'post', params, successData, 2);
    },
    // 获取品牌
    getListBrandInfo: function (brandName) {
        var params = {
            brandName: brandName
        }
        var successData = function (data) {
            if (data.errorCode == 0) {
                customerUpdate.renderGetListBrand(data.data)
            }
        }
        /*return web.doAjax(root.goodsInter.goods_getListBrand, 'post', params, successData, 2);*/
        return web.doAjax(root.serviceProviderManagement.searchBrand, 'post', params, successData, 1);

    },
    renderGetListBrand: function (result) {
        if (result && result.length > 0) {
            var str = '';
            result.forEach(function (item) {
                str += '<li class="brand-item" data-brandId="' + item.brandId + '">' + item.brandName + '</li>';
            });
            $('.brand-warp').html(str)
        } else {
            var empty = ' <li class="brand-item">暂无品牌</li>';
            $('.brand-warp').html(empty)
        }
    },
    // 新增接口
    saveProductByAdminInfo: function (params) {
        var successData = function (data) {
            if (data.errorCode == 0) {
                layer.msg('新增成功!', {offset: 'b'});
                window.setTimeout(function () {
                    parent.layer.closeAll();
                }, 2000)
                window.parent.location.reload();
            } else {
                $('.buttonLeft-name').attr('disabled', false)
                layer.msg(data.msg);
            }
        }
        return web.doAjax(root.serviceProviderManagement.saveProductByAdmin, 'post', params, successData, 1);
    },
    // 修改接口
    updateProductByAdminInfo: function (params) {
        var successData = function (data) {
            if (data.errorCode == 0) {
                layer.msg('修改成功!', {offset: 'b'});
                window.setTimeout(function () {
                    parent.layer.closeAll();
                }, 2000)
                window.parent.location.reload();
            } else {
                $('.buttonLeft-name').attr('disabled', false)
                layer.msg(data.msg);
            }
        }
        return web.doAjax(root.serviceProviderManagement.updateProductByAdmin, 'post', params, successData, 1);

    },
    // 渲染修改信息
    getDetailDataInfo: function (spuId) {
        var params = {
            spuId: spuId
        }
        var successData = function (data) {
            if (data.errorCode == 0) {
                customerUpdate.renderModifyData(data.data)
            }
        }
        return web.doAjax(root.serviceProviderManagement.getFormalProductDetail, 'post', params, successData, 2);
    },
    // 渲染修改信息
    renderModifyData: function (result) {
        var providerName = result.providerName ? result.providerName : '';//服务商
        var channelName = result.channelName ? result.channelName : '';// 专属渠道

        var spuName = result.spuName ? result.spuName : '';//商品名称
        var oneCategoryName = result.oneCategoryName ? result.oneCategoryName : '';//一级名称
        customerUpdate.oneCategoryId = result.oneCategoryId;//一级分类名称id
        customerUpdate.twoCategoryId = result.twoCategoryId;//二级分类名称id
        customerUpdate.threeCategoryId = result.threeCategoryId;// 三级分类名称id
        customerUpdate.categoryId = result.categoryId;//末级分类名称id
        customerUpdate.customerId = result.channelId;
        var twoCategoryName = result.twoCategoryName ? result.twoCategoryName : '';//二级名称
        var threeCategoryName = result.threeCategoryName ? result.threeCategoryName : '';//三级名称
        var fourCategoryName = result.fourCategoryName ? result.fourCategoryName : '';//四级分类
        var classifyHtml = oneCategoryName + ' > ' + twoCategoryName + ' > ' + threeCategoryName + '>' + fourCategoryName;
        customerUpdate.selectFirstClassify = oneCategoryName + '>';
        customerUpdate.selectSecondClassify = oneCategoryName + '>' + twoCategoryName + '>';
        customerUpdate.selectThirdClassify = oneCategoryName + '>' + twoCategoryName + '>' + threeCategoryName;
        customerUpdate.selectFourthClassify = oneCategoryName + '>' + twoCategoryName + '>' + threeCategoryName + '>' + fourCategoryName;
        //var classificationName = result.classificationName ? result.classificationName : '';//归类名称
        var revenueCode = result.revenueCode ? result.revenueCode : '';//税类编码
        var definitionBrandName = result.definitionBrandName;// 自定义品牌名称
        var brandName = result.brandName;//云采品牌
        var origin = result.origin ? result.origin : '';//产地
        var restricted = result.restricted;// 限制类型
        var spuImages = result.spuImages ? result.spuImages : []; //// 渲染图片
        customerUpdate.params.productQualifications = result.productQualifications;//商品资质
        var providerId = result.providerId;//服务商id
        var spuId = result.spuId;// spuId
        var spuCode = result.spuCode;//spu编码
        var brandId = result.brandId;// 品牌id
        var channelId = result.channelId;//渠道id
        var skus = result.skus;//规格信息
        // var material = result.material ? result.material : '';//材质
        // 根据渠道查询指定的区域
        customerUpdate.channelId = result.channelId;//
        customerUpdate.providerId = result.providerId;
        if (brandId) {
            customerUpdate.params.brandId = brandId;
            customerUpdate.params.brandName = result.brandName;
            $('#brandName').val(brandName);
            $('.add-brandName').show();
            $('.add-definedName').hide();
        } else {
            customerUpdate.params.brandId = '';
            customerUpdate.params.brandName = '';
            customerUpdate.params.definitionBrandName = definitionBrandName;
            $('#definitionBrandName').val(definitionBrandName);
            $('.add-definedName').show();
            $('.add-brandName').hide();
        }
        customerUpdate.params.categoryId = result.categoryId;
        // 渲染三级分类
        customerUpdate.params.classificationId = result.classificationId; //归类名称对应id
        customerUpdate.params.channelId = channelId; //用户编码
        customerUpdate.getClassifyInfo(channelId);
        // 归类名称请求
        customerUpdate.getClassIficationAndRevenueInfo(result.categoryId)

        // 详细介绍
        var detail = result.detail;//详细信息
        if (detail) {
            ue.ready(function () {
                UE.getEditor('editor').setContent(detail, false);
            })
        }
        $('#modifyClassifyName').html(providerName);
        $('#modifyChannelName').text(channelName);
        $('#productName').val(spuName);
        $('#inputProductClassify').val(classifyHtml)
        $('#origin').val(origin);
        // $('#material').val(material);
        $('#revenueCode').html(revenueCode);//税类编码
        $("input[name='radio1'][value=" + restricted + "]").prop("checked", true);
        // 渲染图片
        if (spuImages.length > 0) {
            var str = '';
            spuImages.forEach(function (item) {
                var fileName = item.attachmentOriginalName;
                // 添加删除标识
                var ary = item.attachmentUrl.split('/');
                var imgFlag = ary[ary.length - 1];
                var flag = fileName.split('.');
                var flag2 = flag[0]
                str += ' <li class="item-image" data-flag="' + flag2 + '" data-src="' + item.attachmentUrl + '" >' +
                    '                    <img  onclick="customerUpdate.checkBigPic(this)"  title="" src="' + item.attachmentUrl + '" class="mr-10 itemimage" data-name="' + fileName + '">' +
                    '                    <div>' +
                    '                        <span style="color: blue;cursor: pointer" onclick="customerUpdate.deleteImage(\'' + flag2 + '\')">删除</span>' +
                    '                    </div>' +
                    '                </li>';
            });
            $('.upload-img-lists').html(str)
        }

        // 商品资质
        // if (productQualifications) {
        //     $('#downLoadQualification').attr('href', root.orderInter.downLoadFromUrl + '?urlStr=' + productQualifications + '&fileName=下载pdf模板')
        //     $('#qualification-img').show();
        //     $('#downLoadQualification').show();
        //     $('#cancelFile').show();
        //     $('#pdfOperate').hide();
        // } else {
        //     $('#qualification-img').hide();
        //     $('#downLoadQualification').hide();
        //     $('#cancelFile').hide();
        //     $('#pdfOperate').show();
        // }
        if (result.productQualificationAttachments) {
            for (index = 0; index < result.productQualificationAttachments.length; index++) {
                qualificationPDF(result.productQualificationAttachments[index],index);
            }
        }
        
        var saleAreas = result.saleAreas?result.saleAreas:[];
        customerUpdate.saleAreas = saleAreas;
        sessionStorage.setItem('saleAreas',JSON.stringify(customerUpdate.saleAreas))
        if (saleAreas.length > 0) {
            if (saleAreas[0].code == 0) {
                var strArea = '';
                $.each(saleAreas, function (index, item) {
                    strArea += ' <li style="cursor: pointer;display: inline-block;margin-right: 7px" data-code="'+item.code+'">' + item.name + '' +'</li>'
                });
            } else {
                var strArea = '';
                $.each(saleAreas, function (index, item) {
                    strArea += ' <li style="cursor: pointer;display: inline-block;margin-right: 7px" data-code="'+item.code+'">' + item.name + '' +
                        ' <span style="color: #0a60d6">(' + item.children.length + ')</span>' +
                        '</li>'
                });
            }
            $('.saleAreaLists').html(strArea);
        }

        // 渲染规格信息
        customerUpdate.renderProductInfoTable(skus);

        // 修改参数赋值
        customerUpdate.params.spuId = spuId;// spuId
        customerUpdate.params.spuCode = spuCode;// spuCode
        customerUpdate.params.providerId = providerId;// 服务商id
        customerUpdate.params.channelName = channelName

    },
    // 渲染商品信息表格
    renderProductInfoTable: function (skus) {
        var str = '';
        $.each(skus, function (index, item) {
            str += '<tr class="update-tr" style="height: 60px">' +
                '                <td class="col-10-1 text-l" data-skuId="' + item.skuId + '">' +
                '                    <div class="skuCode">' + item.skuCode + '</div>' +
                '                </td>' +
                '                <td class="col-10-1 text-l">' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input type="text"  class="input-text radius modify_specifications"  ' +
                '                       placeholder="请输入规格" ' +
                '                       datatype="/^[\\s\\S]{1,127}$/"' +
                '                        maxlength="127" ' +
                '                        number="127" ' +
                '                        maxlength="127" ' +
                '                        nullmsg="请输入规格" ' +
                '                        errormsg="请输入规格" ' +
                '                        value="'+item.specifications+'"'+
                '                        autocomplete="off">' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '                <td class="col-10-1 text-l">' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input value="'+item.color+'" type="text" class="input-text radius modify_color">' +
                '                    </div>' +
                '                </td>' +
                '                <td class="col-10-1 text-l">' +
                '                    <label class="form-label f-l">¥</label>' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input type="text" class="input-text radius modify_channelPrice" ' +
                '                               nullmsg="请输入售价"' +
                '                               errormsg="请输入售价"' +
                '                               autocomplete="off"' +
                '                               datatype="*"' +
                '                               placeholder="请输入售价" ' +
                '                        value="'+item.channelPrice+'"'+
                '                               onkeyup="!/^(\\d+\\.?)?\\d{0,2}$/.test(this.value)?(this.value=this.value.substring(0, this.value.length-1)): \'\'"/>' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '                <td class="col-10-1 text-l" data-unitId="' + item.unitId + '">' +
                '                           <div style="text-align: left"> ' + item.unitName + '</div>' +
                '                </td>' +
                '                <td class="col-10-1 text-l">' +
                '                   <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input type="text" class="input-text radius modify_deliveryDay"' +
                '                               nullmsg="请输入预计出货日"' +
                '                               errormsg="请输入预计出货日"' +
                '                               autocomplete="off"' +
                '                               datatype="*"' +
                '                               placeholder="请输入预计出货日"' +
                '                               maxlength="5"' +
                '                               number="5"' +
                '                               value="'+item.deliveryDay+'"'+
                '                                onkeyup="value=value.replace(/[^\\d^\\.]+/g,\'\').replace(\'.\',\'$#$\').replace(/\\./g,\'\').replace(\'$#$\',\'.\')"' +
                '                        >' +
                '                       <span style="position: absolute;top: 4px;margin-left: 6px;">天</span>'+
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '                 <td class="col-10-1 text-l">' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input type="text" class="input-text radius modify_miniOrder"' +
                '                               nullmsg="请输入最小起订量"' +
                '                               errormsg="请输入最小起订量"' +
                '                               autocomplete="off"' +
                '                               datatype="*"' +
                '                               placeholder="请输入最小起订量"' +
                '                               maxlength="5"' +
                '                               number="5"' +
                '                               value="'+item.miniOrder+'"'+
                '                               onkeyup="value=value.replace(/[^\\d^\\.]+/g,\'\').replace(\'.\',\'$#$\').replace(/\\./g,\'\').replace(\'$#$\',\'.\')"' +
                '                        >' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '                <td class="col-10-1 text-l">' +
                '                    <div class="formControls col-sm-8" style="width: 75%">' +
                '                        <input' +
                '                                type="text" class="input-text radius modify_maxLong"' +
                '                                onkeyup="value=value.replace(/[^\\d^\\.]+/g,\'\').replace(\'.\',\'$#$\').replace(/\\./g,\'\').replace(\'$#$\',\'.\')"' +
                '                                placeholder="请输入最长边"' +
                '                                maxlength="10"' +
                '                                nullmsg="请输入最长边"' +
                '                                errormsg="小数点后最多输入6位有效数字"' +
                '                                number="10"' +
                '                                datatype="/^[0-9]+(.[0-9]{1,6})?$/"' +
                '                               value="'+item.maxLength+'"'+
                '                        >' +
                '                        <span style="position: absolute;top: 4px;margin-left: 6px;width: 19px;display: inline-block" >cm</span>' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '                 <td class="col-10-1 text-l">' +
                '                    <div class="formControls col-sm-8"  style="width: 75%">' +
                '                        <input' +
                '                                type="text" class="input-text radius modify_maxVolume"' +
                '                                placeholder="请输入体积"' +
                '                                onkeyup="value=value.replace(/[^\\d^\\.]+/g,\'\').replace(\'.\',\'$#$\').replace(/\\./g,\'\').replace(\'$#$\',\'.\')"' +
                '                                maxlength="10"' +
                '                                nullmsg="请输入体积"' +
                '                                errormsg="小数点后最多输入6位有效数字"' +
                '                                autocomplete="off"' +
                '                                number="10"' +
                '                                datatype="/^[0-9]+(.[0-9]{1,6})?$/"' +
                '                               value="'+item.volume+'"'+
                '                        >' +
                '                        <span style="position: absolute;top: 4px;margin-left: 6px;width: 18px;display: inline-block">m³</span>' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '                <td class="col-10-1 text-l">' +
                '                    <div class="formControls col-sm-8"  style="width: 75%">' +
                '                        <input type="text" class="input-text radius modify_weight"' +
                '                               nullmsg="请输入重量"' +
                '                               errormsg="小数点后最多输入6位有效数字"' +
                '                               autocomplete="off"' +
                '                               datatype="/^[0-9]+(.[0-9]{1,6})?$/"' +
                '                               placeholder="请输入重量"' +
                '                               maxlength="10"' +
                '                               number="10"' +
                '                               value="'+item.weight+'"'+
                '                               onkeyup="value=value.replace(/[^\\d^\\.]+/g,\'\').replace(\'.\',\'$#$\').replace(/\\./g,\'\').replace(\'$#$\',\'.\')"' +
                '                        >' +
                '                        <span style="position: absolute;top: 4px;margin-left: 6px;width: 15px;display: inline-block">kg</span>' +
                '                    </div>' +
                '                    <span class="Validform_checktip">' +
                '                           <span class="Validform_checktip"></span>' +
                '                    </span>' +
                '                </td>' +
                '            </tr>';

        });
        $('#modifyTableData').html(str);
/*        // 渲染规格
        $.each($('.modify_specifications'), function (index, item) {
            $(item).val(skus[index].specifications)
        })
        // 渲染颜色
        $.each($('.modify_color'), function (index, item) {
            $(item).val(skus[index].color)
        });
        // 渲染售价
        $.each($('.modify_channelPrice'), function (index, item) {
            $(item).val(skus[index].channelPrice)
        });
        // 渲染预计出货日
        $.each($('.modify_deliveryDay'), function (index, item) {
            $(item).val(skus[index].deliveryDay)
        });
        // 渲染最小起订量
        $.each($('.modify_miniOrder'), function (index, item) {
            $(item).val(skus[index].miniOrder)
        });
        // 最长边
        $.each($('.modify_maxLong'), function (index, item) {
            $(item).val(skus[index].miniOrder)
        });
        //体积
        $.each($('.modify_maxVolume'), function (index, item) {
            $(item).val(skus[index].miniOrder)
        });
        //重量
        $.each($('.modify_weight'), function (index, item) {
            $(item).val(skus[index].miniOrder)
        });*/

    },
    // 根据四级分类查询归类商品
    getClassIficationAndRevenueInfo: function (categoryId) {
        var params = {
            categoryId: categoryId
        }
        var successData = function (data) {
            if (data.errorCode == 0) {
                var result = data.data;
                var str = '';
                if (result.length > 0) {
                    $.each(result, function (index, item) {
                        str += '<option value="' + item.classificationId + '" data-revenueCode="' + item.revenueCode + '">' + item.classificationName + '</option>'
                    });
                    var newStr = '<option value="" selected>请选择归类名称</option>' + str;
                    $('#classifyName').html(newStr)
                } else {
                    var empty = '<option value="" >暂无数据</option>';
                    $('#classifyName').html(empty)
                }
                if (customerUpdate.params.classificationId) {
                    $.each($('#classifyName option'), function (index, item) {
                        if (item.value == customerUpdate.params.classificationId) {
                            item.selected = true;
                        }
                    })
                }
            }
        }
        return web.doAjax(root.serviceProviderManagement.getClassIficationAndRevenueInfo, 'post', params, successData, 1)
    },
    // 上传图片
    uploadImage: function (formData) {
        $.ajax({
            url: root.serviceProviderManagement.uploadImages,
            cache: false,  //禁用缓存
            type: "POST",
            // 告诉jQuery不要去处理发送的数据
            processData: false,
            // 告诉jQuery不要去设置Content-Type请求头
            contentType: false,
            data: formData,
            success: function (data) {
                var result = data.data;
                var fullPath = result[0].imgUrl;
                var fileName = result[0].imgFileName; //attachmentOriginalName
                // 添加删除标识
                var ary = fullPath.split('/');
                var imgFlag = ary[ary.length - 1];
                var flag = fileName.split('.');
                var flag2 = flag[0]
                var str = ' <li class="item-image" data-flag="' + flag2 + '">' +
                    '                    <img title="" src="' + fullPath + '?x-oss-process=style/marking_detail' + '" class="mr-10 itemimage" data-name="' + fileName + '"  onclick="customerUpdate.checkBigPic(this)" >' +
                    '                    <div>' +
                    '                        <span style="color: blue;cursor: pointer" onclick="customerUpdate.deleteImage(\'' + flag2 + '\')">删除</span>' +
                    '                    </div>' +
                    '                </li>';
                $('.upload-img-lists').append(str);
                if ($('.upload-img-lists .item-image').length >= 5) {
                    $('#imgOperate').hide()
                } else {
                    $('#imgOperate').show()
                }
                $('#imgs').val('')
            },
        })

    },
    // 上传商品资质
    uploadQualificationInfo: function (formData) {
        $.ajax({
            url: root.serviceProviderManagement.uploadForIE8,
            cache: false,  //禁用缓存
            type: "POST",
            // 告诉jQuery不要去处理发送的数据
            processData: false,
            // 告诉jQuery不要去设置Content-Type请求头
            contentType: false,
            data: formData,
            success: function (data) {
                var result = JSON.parse(data);
                var fileSize = result[0].fileSize;
                var maxFileSize = 5 * 1024;
                if (fileSize > maxFileSize) {
                    layer.msg('文件大小不能超过5M!');
                    return false
                }
                var pdf = {
                    attachmentOriginalName:result[0].fileName,
                    attachmentUrl:result[0].fullPath
                };
                qualificationPDF(pdf,customerUpdate.params.productQualificationAttachments.length);
            },
        })
    },
    // 点击删除图片
    deleteImage: function (url) {
        var imageLists = $('.item-image');
        $.each(imageLists, function (index, item) {
            var itemUrl = $(item).attr('data-flag');
            if (itemUrl == url) {
                $(item).remove();
                $('#imgOperate').show()
            }
        })
    },
    // 获取单位
    searchUnitInfo: function (unitName) {
        var params = {
            unitName: unitName
        }
        var successData = function (data) {
            if (data.errorCode == 0) {
                if (data.data && data.data.length > 0) {
                    var result = data.data;
                    var str = '';
                    result.forEach(function (item) {
                        str += '<li class="unit-item" data-unitId="' + item.unitId + '" >' + item.unitName + '</li>'
                    });
                    $('.search-unit').html(str)
                } else {
                    var emptyStr = '<li class="unit-item">暂无单位</li>';
                    $('.search-unit').html(emptyStr)
                }
            }
        }
        return web.doAjax(root.serviceProviderManagement.searchUnit, 'post', params, successData, 1)
    },
    // 参数校验
    parameterChecked: function () {
        var judgmentFieldObj = {
            productName: '商品名称不能为空',
            productClassify: '商品分类不能为空',
            classifyName: '归类名称不能为空',
            detail: '详情不能为空',
            salesArea: '请选择销售区域'
        }
        var params = {
            productName: $('#productName').val(),//商品名称
            productClassify: $('#inputProductClassify').val(),//商品分类
            classifyName: $('#classifyName').find('option:selected').val(),//归类名称
            // material: $('#material').val(),//材质
            detail: UE.getEditor('editor').getContent(),//详情
            img: $('.upload-img-lists .item-image').length >= 2 ? true : false,//上传图片
            salesArea: $('.saleAreaLists li').length
        }
        var isFlag = nullValueJudgmentFn(params, judgmentFieldObj);
            if(isFlag){
                var productName = $('#productName').val(); // 商品名称
                var brandName = $('#brandName').val(); // 品牌名称

                if (customerUpdate.params.brandId) {
                    if (productName.indexOf(brandName) == -1) {
                        layer.msg('商品名称中需包含品牌名');
                        return false;
                    }
                }else{
                    var definitionBrandName = $("#definitionBrandName").val();
                    if (productName.indexOf(definitionBrandName) == -1) {
                        layer.msg('商品名称中需包含品牌名');
                        return false;
                    }
                }

                if (productName.indexOf("  ") >= 0) {
                    layer.msg('商品名称中不能包含多个连续空格');
                    return  false;
                }


                var imgLength = $('.upload-img-lists .item-image').length;
                if(imgLength < 2){
                    layer.msg('请最少上传2张图片')
                    return false;
                }

                // 详情
                var detail = UE.getEditor('editor').getContent();//详情
                if (detail) {
                    var detail_img_num = detail.split('<img src=').length - 1;
                    if (detail_img_num < 2) {
                        layer.msg('详细介绍处需上传2张以上图片')
                        return false;
                    }
                }
            }

        return isFlag
    },
    // 点击查看大图
    checkBigPic: function (imgSrc) {
        var imgUrl = $(imgSrc).attr('src')
        var title = '查看图片';
        var url = '../../goods/picShow.html';
        window.event ? window.event.cancelBubble = true : e.stopPropagation();
        sessionStorage.setItem("imgUrl", imgUrl);
        layer_show(title, url, "800", "500");
    },
}
customerUpdate.init();

//资质pdf渲染
function qualificationPDF(pdf,index)
{
    var qualification_Html = "<div class=\"qualification_module\">";
        qualification_Html += "<img class=\"qualification-img\" src=\"../../../img/Pdf.png\">";
        qualification_Html += "<div class=\"qualification_oper\">";
        qualification_Html += "<a href=\"" + root.orderInter.downLoadFromUrl + "?urlStr="+ pdf.attachmentUrl + "&fileName=下载pdf模板\" class=\"downLoadQualification\">点击下载附件查看</a>";
        qualification_Html += "<span class=\"cancelFile\" onclick='delQualification(this,"+ index +")'>删除</span>";
        qualification_Html += "<input type=\"hidden\" name=\"productQualification\" value=\"" + pdf.attachmentUrl + "\">";
        qualification_Html += "</div>";
        qualification_Html += "</div>";
        $("#qualification_list").prepend(qualification_Html);
        customerUpdate.params.productQualificationAttachments.push(pdf);
        if (customerUpdate.params.productQualificationAttachments.length >= 5) {
            $('#pdfOperate').hide();
        }
}

//资质文件删除操作
function delQualification (element,index) {
    $(element).parent().parent(".qualification_module").remove();
    customerUpdate.params.productQualificationAttachments.splice(index,1);
        if (customerUpdate.params.productQualificationAttachments.length < 5) {
            $('#pdfOperate').show();
        }
}